package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.page.TableDataInfo;
import com.fas.common.utils.SecurityUtils;
import com.fas.system.domain.FasFacilitiesTypeDataItem;
import com.fas.system.service.IFasFacilitiesTypeDataItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 设施类型数据项表 Controller
 *
 * @date 2022-07-01
 */
@Api(tags = "设施类型——数据项")
@RestController
@RequestMapping("/system/facilities/type/data")
public class FasFacilitiesTypeDataItemController extends BaseController {

    @Resource
    private IFasFacilitiesTypeDataItemService fasFacilitiesTypeDataItemService;

    @ApiOperation(value = "通过设施类型查询设施数据项列表")
    @GetMapping("/findListById")
    public TableDataInfo findListById(FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem,Integer pageNum,Integer pageSize) {
        startPage();
        return getDataTable(fasFacilitiesTypeDataItemService.findByFacilityId(fasFacilitiesTypeDataItem));
    }

    @ApiOperation(value = "新增设施类型-设施数据项")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        int addMethod = deptId == 100 ? 1 : 2;
        fasFacilitiesTypeDataItem.setAddMethod(addMethod);
        return fasFacilitiesTypeDataItemService.addFasFacilitiesTypeDataItem(fasFacilitiesTypeDataItem);
    }

    @ApiOperation(value = "修改设施类型-设施数据项")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        Long deptId = SecurityUtils.getLoginUser().getDeptId();
        int addMethod = deptId == 100 ? 1 : 2;
        fasFacilitiesTypeDataItem.setAddMethod(addMethod);
        return toAjax(fasFacilitiesTypeDataItemService.editFasFacilitiesTypeDataItem(fasFacilitiesTypeDataItem));
    }

    @ApiOperation(value = "删除设施类型-设施数据项")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") String id) {
        return toAjax(fasFacilitiesTypeDataItemService.deleteFasFacilitiesTypeDataItem(id));
    }

    @ApiOperation(value = "设施类型-设施数据项-是否启用")
    @PostMapping("/enable")
    public AjaxResult enableDataItem(@RequestBody FasFacilitiesTypeDataItem fasFacilitiesTypeDataItem) {
        return toAjax(fasFacilitiesTypeDataItemService.enableDataItem(fasFacilitiesTypeDataItem));
    }

}
